exports.ProgressBar = GL2.Node.subclass(
{
    classname: 'ProgressBar',
    
    initialize: function(model, type) 
    {
		this._image = null;
		this._type = null;
		this._model = null;
		this.setRotation(180);
		this._type = type;
		this._model = model;
    },
	
	createView: function()	
	{
		var fillerBar = this.getBaseResourcePath()+ "bar.png";
		var background = this.getBaseResourcePath()+ "background.png";
		var frame = this.getBaseResourcePath()+ "frame.png";
		
		this._backgroundImage = GLFactory.getSprite([TCUtil.getAdjustedX(0),TCUtil.getAdjustedY(-20)], null, background, [TCUtil.getAdjustedX(10),TCUtil.getAdjustedY(45)]);
		this.addChild(this._backgroundImage);

		this._image = GLFactory.getSprite([TCUtil.getAdjustedX(0),TCUtil.getAdjustedY(-20)], null, fillerBar, [TCUtil.getAdjustedX(10),TCUtil.getAdjustedY(0)]);
		this.addChild(this._image);			
				
		this._frameImage = GLFactory.getSprite([TCUtil.getAdjustedX(0),TCUtil.getAdjustedY(-20)], null, frame, [TCUtil.getAdjustedX(10),TCUtil.getAdjustedY(45)]);
		this.addChild(this._frameImage);
	},
	
	setBarPosition: function()
	{
		var offset = this.getOffsetForPosition();
		if(this._type == kProgressBarType.kProgressBarTypeUpgrade)
		{
			this.setPosition([TCUtil.getAdjustedX(43+offset),TCUtil.getAdjustedY(35)]);
		}
		else
		{
			this.setPosition([TCUtil.getAdjustedX(108+offset),TCUtil.getAdjustedY(35)]);
		}
	},
	
	startProgress: function()
	{
		this._updateProgressTimeout = setInterval(this.updateProgress.bind(this), 1000)
	},
	
	getOffsetForPosition: function()
	{
		var position = this._model.getPosition().getY();
		var offset = 0;
		
		if(position == kStorePlace.kPlaceLeft)
		{
			offset = 0;
		}
		else if(position == kStorePlace.kPlaceCenter)
		{
			offset = 90;
		}
		else if(position == kStorePlace.kPlaceRight)
		{
			offset = 180;
		}
		return offset;
	},
	
	updateProgress: function()
	{
		if(this._type == kProgressBarType.kProgressBarTypeUpgrade)
		{
			var fillerBar = this.getBaseResourcePath()+ "bar.png";
		}
		else
		{
			var fillerBar = this.getBaseResourcePath()+ "bar.png";	
		}
		var currentProgress = this.getCurrentProgressToShow();
		var factor = (currentProgress/100)
		this._image.setImage(fillerBar, [TCUtil.getAdjustedX(10),TCUtil.getAdjustedY(45*factor)], [0,0]);
	},
	
	getCurrentProgressToShow: function()
	{
		if(this._type == kProgressBarType.kProgressBarTypeUpgrade)
		{
			var progressPercentage = this._model.getUpgradeProgressPercentage();	
		}
		else
		{
			var progressPercentage = this._model.getRestockProgressPercentage();
		}

		return progressPercentage;
	},
	
	getBaseResourcePath: function()
	{
		return "./Content/images/gamelayer/environmentlayer/timerbar/";
	},
	
	destroy: function ()
	{
		if(this._image)
		{
			this._image.destroy();
			this._image = null;
		}
		if(this._updateProgressTimeout)
		{
			clearTimeout(this._updateProgressTimeout);
			this._updateProgressTimeout = null;
		}
		if(this._backgroundImage)
		{
			this._backgroundImage.destroy();
			this._backgroundImage = null;
		}
		if(this._frameImage)
		{
			this._frameImage.destroy();
			this._frameImage = null;
		}
		this._model = null;
		this._type = null;

	}
});